import { defineStore } from 'pinia'

export const useNotificationStore = defineStore('notification', {
  state: () => ({
    // 没有被捕获，抛到全局的异常
    exception: null,
    // 服务端发来的通知消息
    notification: null,
  }),
  getters: {},
  actions: {
    /**
     * 设置全局异常，会在vue\vuex的异常处理中注册
     *
     * @param state
     * @param exception
     */
    setException(state, exception) {
      state.exception = exception
    },

    /**
     * 清理全局异常
     *
     * @param state
     */
    clearException(state) {
      state.exception = null
    },
  },
})
